home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 65.3 KB | 2,668 lines | [TEXT/MPS ] |
- {$P}
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UMacApp.TView.p }
- { Copyright © 1984-1990 Apple Computer Inc. All rights reserved. }
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TView.IView(itsDocument: TDocument;
- itsSuperview: TView;
- itsLocation: VPoint;
- itsSize: VPoint;
- itsHSizeDet, itsVSizeDet: SizeDeterminer);
-
- VAR
- fi: FailInfo;
-
- PROCEDURE HandleFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- Free;
- END;
-
- BEGIN
- fSuperview := itsSuperview;
- fSubViews := NIL;
- fDocument := itsDocument;
- fLocation := itsLocation;
- fSize := itsSize;
- fSizeDeterminer[h] := itsHSizeDet;
- fSizeDeterminer[v] := itsVSizeDet;
- fHLDesired := hlOff;
- fIdentifier := kNoIdentifier;
- fShown := TRUE;
- fViewEnabled := TRUE;
- fPrintHandler := NIL;
-
- {$IFC qExperimentalAndUnsupported}
- fFocusRec.Clip := NIL;
- fFocusRec.IsValid := FALSE;
- {$EndC}
-
- IEvtHandler(itsSuperview);
-
- CatchFailures(fi, HandleFailure);
-
- {$IFC qExperimentalAndUnsupported}
- fFocusRec.Clip := MakeNewRgn;
- fFocusRec.isValid := FALSE;
- {$EndC}
-
- IF itsSuperview <> NIL THEN
- itsSuperview.AddSubView(SELF);
- IF itsDocument <> NIL THEN
- itsDocument.AddView(SELF);
- Success(fi);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TView.IRes(itsDocument: TDocument;
- itsSuperview: TView;
- VAR itsParams: Ptr);
-
- BEGIN
- WITH ViewTemplatePtr(itsParams)^ DO
- BEGIN
- IView(itsDocument, itsSuperview, itsLocation, itsSize, SizeDeterminer(itsHSizeDet),
- SizeDeterminer(itsVSizeDet));
- fShown := isShown;
- fViewEnabled := isEnabled;
- fHLDesired := hlOff;
- fIdentifier := thisViewID;
- OffsetPtrWStr(itsParams, SIZEOF(ViewTemplate));
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TView.WRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr);
-
- VAR
- vwPtr: ViewTemplatePtr;
-
- BEGIN
- vwPtr := ViewTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(ViewTemplate),
- LENGTH(gWResType)));
-
- WITH vwPtr^ DO
- BEGIN
- IF fSuperview <> NIL THEN
- itsParentID := fSuperview.fIdentifier
- ELSE
- itsParentID := kNoIdentifier;
- thisViewID := fIdentifier;
- itsLocation := fLocation;
- itsSize := fSize;
- itsVSizeDet := fSizeDeterminer[v];
- itsHSizeDet := fSizeDeterminer[h];
- isShown := fShown;
- isEnabled := fViewEnabled;
- itsSignature := gWResSignature;
- { itsType := gWResType; }
- CopyStr255(gWResType, PRStr(itsType));
- END;
-
- { Everybody gets this far - bump number of views in resource by 1 }
- WITH theResource^^ DO
- numViews := numViews + 1;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAWriteRes}
-
- PROCEDURE TView.WriteRes(theResource: ViewRsrcHndl;
- VAR itsParams: Ptr);
-
- BEGIN
- gWResSignature := 'view'; gWResType := 'TView';
- WRes(theResource, itsParams);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClose}
-
- PROCEDURE TView.Free;
-
- PROCEDURE FreeView(theView: TView);
- BEGIN
- theView.Free; { Type checking is the oat bran of the 70's }
- END;
-
- BEGIN
- { Because RemoveSubView frees the list when it goes empty we don't need to actually free
- the list right here. When each subview gets the free message it removes itself from the
- superview (SELF) and the list may get deleted. Kinda twisty, huh? }
- EachSubView(FreeView);
-
- InvalidateFocus;
- gApplication.InvalidateCursorRgn; {Must re-calc cursor rgn.}
-
- IF SELF = gTarget THEN { Fixup the target chain }
- gApplication.SetTarget(gApplication);
-
- IF fSuperview <> NIL THEN
- fSuperview.RemoveSubView(SELF);
- fSuperview := NIL;
-
- FreeIfObject(fPrintHandler);
- fPrintHandler := NIL;
-
- IF fDocument <> NIL THEN
- fDocument.DeleteView(SELF);
- fDocument := NIL;
-
- {$IFC qExperimentalAndUnsupported}
- IF fFocusRec.Clip <> NIL THEN
- DisposeRgn(fFocusRec.Clip);
- fFocusRec.Clip := NIL;
- fFocusRec.IsValid := FALSE;
- {$EndC}
-
- INHERITED Free;
- END;
- {--------------------------------------------------------------------------------------------------}
- {$S MAActivate}
-
- PROCEDURE TView.Activate(entering: BOOLEAN);
-
- VAR
- newHL: HLState;
-
- PROCEDURE ActivateSubView(theSubView: TView);
-
- BEGIN
- theSubView.Activate(entering);
- END;
-
- BEGIN
- IF entering THEN
- newHL := hlOn
- ELSE
- newHL := hlDim;
- IF Focus & IsVisible THEN
- DoHighlightSelection(fHLDesired, newHL);
- fHLDesired := newHL;
- EachSubView(ActivateSubView);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TView.AddSubView(theSubView: TView);
-
- BEGIN
- IF theSubView <> NIL THEN
- BEGIN
- { Create the subview list if necessary }
- IF fSubViews = NIL THEN
- BEGIN
- fSubViews := NewList;
- {$IFC qDebug}
- fSubViews.SetEltType('TView');
- {$ENDC}
- END;
- if qDebug & (fSubViews.GetSameItemNo(theSubView) <> kEmptyIndex) THEN
- ProgramBreak('in TView.AddSubView: Attempting to add the same subview twice.');
-
- fSubViews.InsertLast(theSubView);
-
- theSubView.fSuperview := SELF;
- IF theSubView.fNextHandler = NIL THEN { If necessary, }
- theSubView.fNextHandler := SELF; { …hook it up to an event hander chain. }
-
- theSubView.InvalidateFocus; { the new subview may have been focused }
-
- theSubView.BeInPort(GetGrafPort);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.AdjustSize;
-
- VAR
- newSize: VPoint;
-
- PROCEDURE AdjustSubViewSize(theSubView: TView);
-
- BEGIN
- theSubView.AdjustSize;
- END;
-
- BEGIN
- newSize := fSize;
- ComputeSize(newSize);
- {$Push} {$H-}
- IF NOT EqualVPt(newSize, fSize) THEN
- {$Pop}
- BEGIN
- Resize(newSize.h, newSize.v, kInvalidate);
- DoPagination;
- END
- ELSE
- EachSubView(AdjustSubViewSize);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.Adorn(area: Rect;
- itsPenSize: Point;
- itsAdornment: CntlAdornment);
-
- CONST
- CntlFrame = [adnLineTop, adnLineLeft, adnLineBottom, adnLineRight];
-
- VAR
- shadowed: BOOLEAN;
- savedPenState: PenState;
-
- PROCEDURE XFrameOval;
-
- BEGIN
- FrameOval(area);
- END;
-
- PROCEDURE XFrameRRect;
-
- BEGIN
- FrameRoundRect(area, 16, 16);
- END;
-
- PROCEDURE DrawWithShadow(PROCEDURE DrawCmd);
-
- LABEL 1;
-
- VAR
- drawRgn: RgnHandle;
- shadowRgn: RgnHandle;
- fi: FailInfo;
-
- PROCEDURE HandleFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- { If we fail allocating memory for the regions, dispose of the regions if
- they exist and continue}
- GOTO 1;
- END;
-
- BEGIN
- IF shadowed THEN
- BEGIN
- shadowRgn := NIL; {In case we creating drawRgn fails}
- CatchFailures(fi, HandleFailure);
- drawRgn := MakeNewRgn;
- shadowRgn := MakeNewRgn;
-
- OpenRgn;
- DrawCmd;
- CloseRgn(drawRgn);
-
- CopyRgn(drawRgn, shadowRgn);
- OffsetRgn(shadowRgn, itsPenSize.h, itsPenSize.v);
- DiffRgn(shadowRgn, drawRgn, shadowRgn);
- PaintRgn(shadowRgn);
- Success(fi);
- 1:
- IF drawRgn <> NIL THEN
- DisposeRgn(drawRgn);
- IF shadowRgn <> NIL THEN
- DisposeRgn(shadowRgn);
- END;
- DrawCmd;
- END;
-
- PROCEDURE DrawLine(vhs: VHSelect;
- lh, lv, lto: INTEGER);
-
- BEGIN
- MoveTo(lh, lv);
- CASE vhs OF
- h:
- Line(lto - lh, 0);
- v:
- Line(0, lto - lv);
- END;
- END;
-
- BEGIN
- IF itsAdornment <> [] THEN { Only do this if adorning is asked for }
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
- GetPenState(savedPenState);
- PenNormal;
- PenSize(itsPenSize.h, itsPenSize.v);
-
- shadowed := adnShadow IN itsAdornment;
- IF shadowed THEN
- SubPt(itsPenSize, area.botRight);
-
- IF adnOval IN itsAdornment THEN
- DrawWithShadow(XFrameOval);
-
- IF adnRRect IN itsAdornment THEN
- DrawWithShadow(XFrameRRect);
-
- IF itsAdornment >= CntlFrame THEN { Special case for whole rect! }
- BEGIN
- FrameRect(area);
- IF shadowed THEN
- WITH area DO
- BEGIN
- DrawLine(h, left + itsPenSize.h, bottom, right);
- DrawLine(v, right, top + itsPenSize.v, bottom);
- END;
- END
- ELSE
- WITH area DO
- BEGIN { No shadows for single lines }
- IF adnLineTop IN itsAdornment THEN
- DrawLine(h, left, top, right);
- IF adnLineLeft IN itsAdornment THEN
- DrawLine(v, left, top, bottom);
- IF adnLineBottom IN itsAdornment THEN
- DrawLine(h, left, bottom - itsPenSize.v, right);
- IF adnLineRight IN itsAdornment THEN
- DrawLine(v, right - itsPenSize.h, top, bottom);
- END;
- SetPenState(savedPenState);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$Push} {$IFC qTrace} {$D+} {$ENDC}
- {$S MADebug}
-
- PROCEDURE TView.AssumeFocused;
-
- VAR
- myself: TView;
- aString: Str255;
- aStringPtr: MANamePtr;
-
- BEGIN
- IF gAssumeFocused THEN
- IF NOT IsFocused THEN
- BEGIN
- myself := SELF;
- WrLblField('Failed AssumeFocused. View', @myself, bObject);
- aStringPtr := MANamePtr(@aString);
- GetClassNameFromID(GetClassID(SELF), aStringPtr^);
- Write(', ClassName=', aString, ', InspectorName=');
- GetInspectorName(aString);
- WRITELN(aString);
- ProgramBreak('');
- END;
- END;
- {$Pop}
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.AttachPrintHandler(itsPrintHandler: TPrintHandler);
-
- BEGIN
- fPrintHandler := itsPrintHandler;
- DoCheckPrinter;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.BeInPort(itsPort: GrafPtr);
-
- PROCEDURE NotifySubView(theSubView: TView);
-
- BEGIN
- theSubView.BeInPort(itsPort);
- END;
-
- BEGIN
- IF (itsPort <> NIL) & (fPrintHandler <> NIL) THEN
- DoCheckPrinter;
- EachSubView(NotifySubView);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.BeInScroller(itsScroller: TScroller);
-
- VAR
- scrollLimits: VPoint;
-
- BEGIN
- IF itsScroller <> NIL THEN
- BEGIN
- scrollLimits := fSize;
- {$Push} {$H-}
- AddVPt(fLocation, scrollLimits);
- {$Pop}
- itsScroller.SetScrollLimits(scrollLimits, kDontRedraw);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.CalcMinSize(VAR minSize: VPoint);
-
- BEGIN
- minSize := fSize;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.ClipFurtherTo(r: Rect;
- hDeltaOrg, vDeltaOrg: INTEGER);
- { Set clipping to: (<current clipping> INTERSECT r) OFFSET-BY (hDeltaOrg, vDeltaOrg) }
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- UseTempRgn('ClipFurtherTo');
- {$ENDC}
-
- RectRgn(gTempRgn, r);
- SectRgn(thePort^.clipRgn, gTempRgn, gTempRgn);
- IF (hDeltaOrg <> 0) | (vDeltaOrg <> 0) THEN
- OffsetRgn(gTempRgn, hDeltaOrg, vDeltaOrg);
- SetClip(gTempRgn);
-
- {$IFC qDebug}
- DoneWithTempRgn;
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClose}
-
- PROCEDURE TView.Close;
-
- VAR
- lastCommand: TCommand;
-
- PROCEDURE CloseSubView(theSubView: TView);
-
- BEGIN
- theSubView.Close;
- END;
-
- BEGIN
-
- { ??? Seems like we should notify the world that we're closing instead of groping around for
- stuff like the last command… }
- lastCommand := GetLastCommand;
- IF (lastCommand <> NIL) & (lastCommand.fView = SELF) THEN
- CommitLastCommand;
-
- EachSubView(CloseSubView);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.ComputeSize(VAR newSize: VPoint);
-
- VAR
- dimension: VCoordinate;
- vhs: VHSelect;
- minSize: VPoint;
-
- BEGIN
- CalcMinSize(minSize);
-
- { Adjust view size based on size determiners. }
-
- FOR vhs := v TO h DO
- BEGIN
- dimension := minSize.vh[vhs]; { Set dimension to a default }
- CASE fSizeDeterminer[vhs] OF
- sizeVariable: ; { For sizeVariable dimension is already set
- correctly }
- sizeFixed:
- dimension := fSize.vh[vhs];
- sizeRelSuperView:
- dimension := newSize.vh[vhs]; { newSize set in SuperViewChangedSize }
- sizeSuperView:
- IF fSuperview <> NIL THEN
- dimension := fSuperview.fSize.vh[vhs];
- sizePage:
- { If there is no printhandler we can defer until one is attached }
- IF fPrintHandler <> NIL THEN
- dimension := fPrintHandler.fViewPerPage.vh[vhs];
- sizeFillPages:
- { If there is no printhandler we can defer until one is attached }
- IF fPrintHandler <> NIL THEN
- dimension := Min(RoundUp(minSize.vh[vhs], fPrintHandler.fViewPerPage.vh[vhs]),
- kMaxCoord);
- END;
- newSize.vh[vhs] := dimension;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.ContainsClipType(aType: ResType): BOOLEAN;
-
- VAR
- offset: LONGINT;
-
- BEGIN
- ContainsClipType := (GetScrap(NIL, aType, offset) > 0)
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.ContainsMouse(theMouse: VPoint): BOOLEAN;
-
- VAR
- extent: VRect;
-
- BEGIN
- GetExtent(extent);
- ContainsMouse := isShown & PtInVRect(theMouse, extent);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.CountSubViews: INTEGER;
-
- BEGIN
- IF fSubViews <> NIL THEN
- CountSubViews := fSubViews.GetSize
- ELSE
- CountSubViews := 0;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.DoBreakFollowing(vhs: VHSelect;
- prevBreak: VCoordinate;
- VAR automatic: BOOLEAN): VCoordinate;
-
- BEGIN
- DoBreakFollowing := fPrintHandler.BreakFollowing(vhs, prevBreak, automatic);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.DoCalcPageStrips(VAR pageStrips: Point);
-
- BEGIN
- fPrintHandler.CalcPageStrips(pageStrips);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
- {$S MANonRes}
-
- PROCEDURE TView.DoCalcViewPerPage(VAR viewPerPage: VPoint);
-
- BEGIN
- viewPerPage := fSize; {in case fPrintHandler is vacuous}
- fPrintHandler.CalcViewPerPage(viewPerPage);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DoCheckPrinter;
-
- BEGIN
- fPrintHandler.CheckPrinter
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DoChoice(origView: TView;
- itsChoice: INTEGER);
-
- BEGIN
- IF fSuperview <> NIL THEN
- fSuperview.DoChoice(origView, itsChoice)
- ELSE
- INHERITED DoChoice(origView, itsChoice);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DoDrawPrintFeedback(area: Rect);
-
- BEGIN
- IF qDebug THEN
- AssumeFocused;
-
- IF fPrintHandler <> NIL THEN
- fPrintHandler.DrawPrintFeedback(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DoDrawPageBreak(vhs: VHSelect;
- whichBreak: INTEGER;
- loc: VCoordinate;
- automatic: BOOLEAN);
-
- BEGIN
- fPrintHandler.DrawPageBreak(vhs, whichBreak, loc, automatic);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DoHighlightSelection(fromHL, toHL: HLState);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- FUNCTION TView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
-
- BEGIN
- CASE aCmdNumber OF
- cPrViewBase..cPrViewMax, cPrFileBase..cPrFileMax:
- IF fPrintHandler <> NIL THEN
- DoMenuCommand := fPrintHandler.DoMenuCommand(aCmdNumber)
- ELSE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- OTHERWISE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- FUNCTION TView.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand;
- { Its easy to get simple tracking that feeds back into your view. Just create a command!
- VAR
- aCommand: TNoChangesCommand;
-
- BEGIN
- NEW(aCommand);
- FailNIL(aCommand);
- aCommand.INoChangesCommand(cNoCommand, fDocument, SELF, GetScroller(FALSE));
- fTracksMouse := TRUE;
- DoMouseCommand := aCommand;
- END;
- }
-
- BEGIN
- DoMouseCommand := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.DoPagination;
-
- BEGIN
- IF fPrintHandler <> NIL THEN
- fPrintHandler.RedoPageBreaks
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.DoPrinterChanged;
-
- BEGIN
- IF fPrintHandler <> NIL THEN
- fPrintHandler.PrinterChanged;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAPrint}
-
- PROCEDURE TView.DoSetPageOffset(coord: VPoint);
-
- BEGIN
- fPrintHandler.SetPageOffset(coord);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.DoSetCursor(localPoint: Point;
- cursorRgn: RgnHandle): BOOLEAN;
-
- BEGIN
- { Our default is to claim the cursor as an arrow for the default cursor region. }
- IF qDebug THEN
- AssumeFocused;
-
- GetDefaultCursorRgn(localPoint, cursorRgn);
-
- SetCursor(arrow);
-
- DoSetCursor := TRUE;
-
- { If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRgn or
- WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
-
- P.S. In debug this is checked for in our original caller: TApplication.TrackMouse. }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.GetDefaultCursorRgn(localPoint: Point;
- cursorRgn: RgnHandle);
- CONST
- kRgnHandleTooBig = 16*1024; { regions > 16K don't work too well, !!!
- move this to the interfaces soon... }
-
- VAR
- r: Rect;
- rgnHandleWasTooBig: Boolean;
-
- PROCEDURE RemoveSubViewRgn(theSubView: TView);
-
- VAR
- vFrame: VRect;
- frame: Rect;
-
- BEGIN
- IF NOT rgnHandleWasTooBig THEN
- BEGIN
- theSubView.GetFrame(vFrame); { Remember, the frame is in OUR coordinate
- system }
- ViewToQDRect(vFrame, frame);
- RectRgn(gTempRgn, frame);
- DiffRgn(cursorRgn, gTempRgn, cursorRgn); { Remove the subview from the claimed rgn }
-
- IF (GetHandleSize(Handle(cursorRgn)) > kRgnHandleTooBig) | (MemError <> NoErr) THEN
- BEGIN
- rgnHandleWasTooBig := TRUE;
- SetEmptyRgn(cursorRgn);
- END;
- END;
- END;
-
- BEGIN
- { If we get all the way to this view without any other view having claimed the
- cursor its because no superview handled it in a "HandleCursor" and no subview handled it
- in a "DoSetCursor" thus there is a _very_ high probability that this view should set the cursor.
- Just in case though, we remove the frames.
-
- If a containing view wishes to set the cursor for itself AND all its subview, the
- place to do that is in our caller: HandleCursor. See HandleCursor in the homebrew controls
- TDialogView subclass in DemoDialogs.
-
- This strategy lets MacApp provide the _largest_ possible cursor rgn, as a default. This way
- windows, controls, background views, etc can have nice big cursor rgns but the developer can
- wrest control if they care to. }
-
- IF qDebug THEN
- AssumeFocused;
-
- GetQDExtent(r);
- RectRgn(cursorRgn, r);
-
- {$IFC qDebug}
- UseTempRgn('TView.GetDefaultCursorRgn, RemoveSubViewRgn');
- {$EndC}
-
- rgnHandleWasTooBig := FALSE;
- EachSubView(RemoveSubViewRgn); { We won't claim subview's territory }
-
- { Make sure the cursorpoint is _still_ included }
- WITH localPoint DO
- SetRectRgn(gTempRgn, h, v, h + 1, v + 1);
- UnionRgn(gTempRgn, cursorRgn, cursorRgn);
-
- {$IFC qDebug}
- DoneWithTempRgn;
- {$ENDC}
-
- { If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRgn or
- WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
-
- P.S. In debug this is checked for in our original caller: TApplication.TrackMouse. }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DoSetupMenus;
-
- BEGIN
- INHERITED DoSetupMenus;
-
- IF fPrintHandler <> NIL THEN
- fPrintHandler.DoSetupMenus;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.Draw(area: Rect);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$IFC qExperimentalAndUnsupported}
- {$S MAViewRes}
-
- PROCEDURE TView.DoOffScreen(PROCEDURE WhatToDo);
- {$IFC qExperimentalAndUnsupported}
-
- TYPE
- BitMapPtr = ^BitMap;
-
- VAR
- visRect: Rect;
- gblVisRect: Rect;
-
- cGrafPortPtr: CGrafPtr;
- theGrafPort: GrafPtr;
- Iscolor: BOOLEAN;
-
- PROCEDURE DoColor;
-
- VAR
-
- theBits: Handle;
- mfBits: BOOLEAN; { true if theBits were allocated in MF Temp mem only needed for pre-
- system 7.0 compatibility since in sys7 you can make mem mgr calls on MF memory. }
- anErr: OSErr;
- pm: PixMapHandle;
- oldpm: PixMapHandle;
- bmp: BitMapPtr;
- pixmapsize: LONGINT;
- rowsize: INTEGER;
- tempCTab: CTabHandle;
- theMaxDevice: GDHandle;
- oldDevice: GDHandle;
- pixelsize: INTEGER;
- fi: FailInfo;
-
- PROCEDURE HdlDoColor(error: INTEGER; message: LONGINT);
-
- BEGIN
- { Restore sanity }
- SetPort(theGrafPort);
- SetPortPix(oldpm);
- SetGDevice(oldDevice);
- IF theBits <> NIL THEN
- BEGIN
- IF mfBits THEN
- MFTempDisposHandle(theBits, anErr)
- ELSE
- theBits := DisposeIfHandle(theBits);
- END;
- theBits := NIL;
-
- IF pm <> NIL THEN
- DisposPixMap(pm);
-
- END;
-
- BEGIN
- theBits := NIL;
- pm := NIL;
- mfBits := FALSE;
- oldpm := cGrafPortPtr^.portPixMap;
-
- { Determine the bit depth required for the drawing }
- gblVisRect := visRect;
- WITH gblVisRect DO
- BEGIN
- LocalToGlobal(topleft);
- LocalToGlobal(botRight);
- END;
- theMaxDevice := GetMaxDevice(gblVisRect);
- pixelsize := theMaxDevice^^.gdPMap^^.pixelsize;
- {set the current device to the max device}
- oldDevice := GetGDevice; {save theGDevice so we can restore it later}
-
- CatchFailures(fi, HdlDoColor);
- SetGDevice(theMaxDevice); {Set to the maxdevice}
-
- IF gIntenseDebugging THEN
- BEGIN
- wrlblptr(' currentdevice', GetGDevice);
- WRITELN;
- END;
-
- pm := NewPixMap; {create the pix map (duplicate existing)}
- IF pm = NIL THEN
- SetGDevice(oldDevice)
- ELSE
- BEGIN
- tempCTab := theMaxDevice^^.gdPMap^^.pmtable;
- IF HandToHand(Handle(tempCTab)) <> NoErr THEN {duplicate old color table}
- BEGIN
- SetGDevice(oldDevice);
- DisposPixMap(pm);
- pm := NIL;
- END
- ELSE
- BEGIN
- Handle(pm^^.pmtable) := DisposeIfHandle(pm^^.pmtable); { release the dummy ctab that
- NewPixMap allocates}
- pm^^.pmtable := tempCTab;
-
- IF gIntenseDebugging THEN
- BEGIN
- WRITELN(' color quickdraw port');
- WrLblRect(' gblvisrect', gblVisRect);
- WRITELN;
- WRITELN(' pixel size = ', pixelsize);
- WrLblHexInt(' old rowbytes=', pm^^.rowbytes);
- WRITELN;
- END;
-
- WITH visRect DO
- BEGIN
- rowsize := ((IntMultiply((right - left - 1), pixelsize) + 15) DIV 16) * 2;
- pixmapsize := IntMultiply(bottom - top, rowsize);
- END;
-
- IF gConfiguration.hasTempMem THEN { try drinking at the MultiFinder™ well first }
- BEGIN
- theBits := MFTempNewHandle(pixmapsize, anErr);
- IF (theBits <> NIL) & (gConfiguration.systemVersion < $700) THEN
- mfBits := TRUE;
- END;
-
- IF theBits = NIL THEN { couldn't get mfmem try in heap }
- theBits := NewPermHandle(pixmapsize);
-
- IF gIntenseDebugging THEN
- WRITELN(' bit map size=', pixmapsize);
-
- IF theBits <> NIL THEN
- BEGIN
- pm^^.rowbytes := BOR(rowsize, $8000); {High bit is set to indicate that it is a pix
- map}
- pm^^.pixelsize := pixelsize;
-
- IF mfBits THEN
- MFTempHLock(theBits, anErr)
- ELSE
- LockHandleHigh(theBits);
-
- pm^^.baseaddr := QDPtr(theBits^);
- pm^^.bounds := visRect;
-
- {Intercept the grafport's Pix map and use the offscreen map instead}
- SetPortPix(pm);
-
- EraseRect(visRect);
- CopyBits(BitMapPtr(oldpm^)^, thePort^.portBits, visRect, visRect, srcOr, NIL);
- END
- ELSE
- BEGIN
- IF gIntenseDebugging THEN
- BEGIN
- WRITELN('could not allocate pixmap size=', pixmapsize);
- END;
- DisposPixMap(pm);
- pm := NIL;
- END;
- END;
- END;
-
- WhatToDo;
-
- IF theBits <> NIL THEN
- BEGIN
-
- { What to do may have changed the focus }
- IF Focus THEN
- BEGIN
- IF gIntenseDebugging THEN
- BEGIN
- wrlblptr(' currentdevice', GetGDevice);
- WRITELN;
- END;
-
- {restore the screen's pix map}
- SetPortPix(oldpm);
- bmp := BitMapPtr(pm^);
-
- {restore the screen's device}
-
- SetGDevice(oldDevice);
-
- IF gIntenseDebugging THEN
- BEGIN
- WrLblHexInt(' rowbytes', bmp^.rowbytes);
- WRITELN(' color copy');
- END;
-
- { blit back to the real screen }
- CopyBits(bmp^, thePort^.portBits, visRect, visRect, srcCopy, NIL);
- END
- ELSE IF qDebug THEN
- ProgramBreak('in TView.DoOffScreen: Couldn''t regain focus');
-
- DisposPixMap(pm);
- pm := NIL;
-
- IF mfBits THEN
- MFTempDisposHandle(theBits, anErr)
- ELSE
- theBits := DisposeIfHandle(theBits);
- theBits := NIL;
-
- Success(fi);
- END;
- END;
-
- PROCEDURE DoBW;
-
- VAR
-
- theBits: Handle;
- mfBits: BOOLEAN; { true if theBits were allocated in MF Temp mem }
- anErr: OSErr;
- bm: BitMap;
- oldBits: BitMap;
- pm: PixMapHandle;
- bmp: BitMapPtr;
- rowsize: INTEGER;
- fi: FailInfo;
-
- PROCEDURE HdlDoBW(error: INTEGER; message: LONGINT);
-
- BEGIN
- { Restore law and order }
- SetPort(theGrafPort);
- SetPortBits(oldBits);
-
- IF theBits <> NIL THEN
- BEGIN
- IF mfBits THEN
- MFTempDisposHandle(theBits, anErr)
- ELSE
- theBits := DisposeIfHandle(theBits);
- END;
- theBits := NIL;
- END;
-
- BEGIN
- theBits := NIL;
- mfBits := FALSE;
- oldBits := thePort^.portBits; { Handy to have for failures too }
-
- CatchFailures(fi, HdlDoBW);
- IF gIntenseDebugging THEN
- WRITELN(' quickdraw port');
-
- WITH visRect DO
- BEGIN
- bm.rowbytes := (((right - left - 1) DIV 16) + 1) * 2;
- IF gConfiguration.hasTempMem THEN
- BEGIN
- theBits := MFTempNewHandle(IntMultiply(bottom - top, bm.rowbytes), anErr);
- IF (theBits <> NIL) & (gConfiguration.systemVersion < $700) THEN
- mfBits := TRUE;
- END;
-
- IF theBits = NIL THEN
- theBits := NewPermHandle(IntMultiply(bottom - top, bm.rowbytes));
- END;
-
- IF theBits <> NIL THEN
- BEGIN
- IF mfBits THEN
- MFTempHLock(theBits, anErr)
- ELSE
- LockHandleHigh(theBits);
-
- bm.baseaddr := QDPtr(theBits^);
- bm.bounds := visRect;
-
- IF gIntenseDebugging THEN
- WRITELN('setting new port bits');
- SetPortBits(bm);
-
- EraseRect(visRect);
- CopyBits(oldBits, thePort^.portBits, visRect, visRect, srcOr, NIL);
-
- WhatToDo;
-
- { What to do may have changed the focus }
- IF Focus THEN
- BEGIN
- { blit back to the real screen }
- SetPortBits(oldBits);
- CopyBits(bm, thePort^.portBits, visRect, visRect, srcCopy, NIL);
- END
- ELSE IF qDebug THEN
- ProgramBreak('in TView.DoOffScreen: Couldn''t regain focus');
-
- IF mfBits THEN
- MFTempDisposHandle(theBits, anErr)
- ELSE
- theBits := DisposeIfHandle(theBits);
- theBits := NIL;
-
- Success(fi);
- END
- ELSE
- WhatToDo;
-
- END;
-
- BEGIN
- { An adaptation of Rob Hawley's excellent offscreen support.
- !!! Enhancements would include:
- • parameters to the WhatToDo procedure to give it control over blitting.
- • the ability to stay offscreen for extended periods and blit back periodically
- (this would be useful in scrolling).
- • the ability to defeat offscreening for views that have their own offscreen bitmaps
- already (ala DoubleVision)
- • the ability to disable software double-buffering if hardware double-buffering is
- available (say from a third party video-card)
- • controllable bit-depth (don't always need all 32 bits)
- }
- IF Focus THEN
- BEGIN
- GetVisibleRect(visRect);
- IF gIntenseDebugging THEN
- BEGIN
- WRITELN('TView.DoOffScreen');
- WrLblRect(' visrect', visRect);
- WRITELN;
- END;
-
- IF NOT EmptyRect(visRect) THEN
- BEGIN
-
- InsetRect(visRect, - 2, - 2); { A little extra space for good measure }
-
- theGrafPort := thePort;
- cGrafPortPtr := CGrafPtr(thePort);
- Iscolor := cGrafPortPtr^.portversion = $C000;
-
- IF gIntenseDebugging THEN
- BEGIN
- WrLblRect(' clipped visRect', visRect);
- WRITELN;
- WrLblRect(' update region', thePort^.visRgn^^.rgnbBox);
- WRITELN;
- WrLblHexInt(' cGrafPortPtr^.portversion', cGrafPortPtr^.portversion);
- WRITELN;
- END;
-
- IF Iscolor THEN
- DoColor
- ELSE
- DoBW;
- END;
- END;
-
- {$EndC}
- END;
- {$EndC}
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.DrawContents;
-
- VAR
- visRect: Rect;
- aFocusRec: FocusRec;
- displaying: BOOLEAN;
- fi: FailInfo;
- {$IFC qExperimentalAndUnsupported}
- oldgEnableDoubleBuffering: BOOLEAN;
- {$EndC}
-
- PROCEDURE HdlDrawContents(error: OSErr;
- message: LONGINT);
-
- BEGIN
- {$IFC qExperimentalAndUnsupported}
- gEnableDoubleBuffering := oldgEnableDoubleBuffering;
- {$ELSEC}
- IF aFocusRec.Clip <> NIL THEN
- DisposeRgn(aFocusRec.Clip);
- {$EndC}
- END;
-
- PROCEDURE DrawSubViewContents(theSubView: TView);
-
- VAR
- itsFrame: VRect;
- itsQDFrame: Rect;
-
- BEGIN
- IF theSubView.isShown THEN
- BEGIN
- {$IFC qExperimentalAndUnsupported}
- theSubView.DrawContents;
-
- {$ELSEC}
- { See if this subview is visible. Kinda yucko but still cheaper than Focus/IsVisible }
- theSubView.GetFrame(itsFrame);
- ViewToQDRect(itsFrame, itsQDFrame);
- IF RectInRgn(itsQDFrame, thePort^.clipRgn) | NOT displaying THEN
- BEGIN
- theSubView.DrawContents;
- SetFocus(aFocusRec); { Restore my focus. }
- END;
- {$EndC}
- END;
- END;
-
- PROCEDURE DoDrawContents;
-
- BEGIN
- IF Focus THEN
- BEGIN
- GetVisibleRect(visRect);
- displaying := NOT (gPrinting | gDrawingPictScrap);
- IF NOT EmptyRect(visRect) | NOT displaying THEN
- BEGIN
- Draw(visRect);
-
- {$IFC qExperimentalAndUnsupported}
- EachSubView(DrawSubViewContents);
-
- {$ELSEC}
- IF CountSubViews > 0 THEN
- BEGIN
- { Cobbler's kid shouldn't go barefoot. We use our own stuff here now until the new
- fast focusing is in. (post 2.0)
-
- Focusing is currently (unfortunately) too expensive to do here. So we save the
- current focus so that it can be restored quickly. Hopefully none of the subiew's
- drawing will invalidate this saved focus or we're dead meat. Well that's part of the
- problem with the current focus save restore.
-
- ??? Could get/set focus deal with chained focusrecs that can be invalidated by
- invalidatefocus for safer usage. Can most of this muck be avoided by fast focusing? }
- CatchFailures(fi, HdlDrawContents);
- aFocusRec.Clip := NIL;
- aFocusRec.Clip := MakeNewRgn;
- GetFocus(aFocusRec); { Save the superview's focus (That's me). }
-
- EachSubView(DrawSubViewContents);
- Success(fi);
-
- DisposeRgn(aFocusRec.Clip);
- aFocusRec.Clip := NIL;
- END;
- {$EndC}
-
- IF displaying THEN
- BEGIN
-
- {$IFC qExperimentalAndUnsupported}
- IF Focus THEN;
- {$EndC}
-
- DoHighlightSelection(hlOff, fHLDesired);
- IF fPrintHandler <> NIL THEN
- DoDrawPrintFeedback(visRect);
- END;
-
- END;
- END;
- END;
-
- BEGIN
-
- {$IFC qExperimentalAndUnsupported}
- IF Focus & IsVisible THEN
- BEGIN
- IF gEnableDoubleBuffering & NOT (gPrinting | gDrawingPictScrap) THEN
- BEGIN
- oldgEnableDoubleBuffering := gEnableDoubleBuffering;
- gEnableDoubleBuffering := FALSE; { so subviews won't attempt to do off screen
- }
- CatchFailures(fi, HdlDrawContents);
- DoOffScreen(DoDrawContents);
- Success(fi);
- gEnableDoubleBuffering := oldgEnableDoubleBuffering;
- END
- ELSE
- DoDrawContents;
- END;
- {$ELSEC}
- DoDrawContents;
- {$EndC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.EachSubView(PROCEDURE DoToSubView(theSubView: TView));
-
- BEGIN
- IF fSubViews <> NIL THEN
- fSubViews.Each(DoToSubView);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.FindSubView(itsIdentifier: IDType): TView;
-
- VAR
- foundView: TView;
- dummyView: TView;
-
- FUNCTION TestSubID(theSubView: TView): BOOLEAN;
-
- BEGIN
- IF LONGINT(theSubView.fIdentifier) = LONGINT(itsIdentifier) THEN
- foundView := theSubView
- ELSE
- dummyView := theSubView.FirstSubViewThat(TestSubID);
- TestSubID := foundView <> NIL;
- END;
-
- BEGIN
- IF LONGINT(fIdentifier) = LONGINT(itsIdentifier) THEN
- foundView := SELF
- ELSE
- BEGIN
- foundView := NIL;
- dummyView := FirstSubViewThat(TestSubID);
- END;
- {$IFC qDebug}
- IF foundView = NIL THEN
- BEGIN
- WRITELN('Unable to find subview: ''', itsIdentifier, '''');
- IF gIntenseDebugging THEN
- ProgramBreak('!');
- END;
- {$ENDC}
- FindSubView := foundView;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.FirstSubViewThat(FUNCTION TestSubView(theSubView: TView): BOOLEAN): TView;
-
- BEGIN
- {$Push} {$R-} { Look, its ok to type coerce a nil
- reference but the world gets really crazy
- if the TestSubView function (or something)
- frees the view that is returned. That's
- why we defeat the run-time coercion
- testing that is done if range checking is
- true. }
- IF fSubViews <> NIL THEN
- FirstSubViewThat := TView(fSubViews.FirstThat(TestSubView))
- ELSE
- FirstSubViewThat := NIL;
- {$Pop}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.Focus: BOOLEAN;
-
- CONST
- kMaxOriginFixup = 1024; { The maximum amout by which to _fixup_ (not
- offset) the QD origin when focusing. This
- allows patterns and pixpats to be pinned
- to global space as they were intended. See
- note below. Larger values than this may be
- required for _extremely_ complex pixpats
- (not patterns as they are restricted to 8
- bit repetition.) The reason that the fixup
- is restricted is that you don't want to
- run off the end of QD space and we already
- have slop allowance of about 2k in
- ViewCoords.p. Good Luck Jim! (??? should
- this be settable for the adventurous?) }
-
- VAR
- tempLongOffset: VCoordinate;
- relOrigin: VPoint;
- qdFrame: Rect;
- aRect: Rect;
- viewRect: VRect;
- visRect: VRect;
- myFrame: VRect;
- vhs: VHSelect;
- {$IFC qDebug}
- currentPort: GrafPtr;
- {$ENDC}
- {$IFC qExperimentalAndUnsupported}
- aFocusRec: FocusRec;
- {$ENDC}
-
-
- { thanks kaar! (memorial hack)
- The problems with pattern alignment when using 32bit views occured when virtual
- origin of the port no longer had coordinates that were multiples of 8. This
- could occur if, for example, one scrolled a view by increments of other than 8,
- 16, or other multiple of 8.
-
- The reason for this was due to the way the origin of the port was handled for
- large views. In large views, the origin is always set to (0, 0), and the origin
- is maintained in gLongOffset. When this happens, patterns are always draw as if
- we are always scrolled to the extreme top and left of our view. However, this
- is not always true. It could be that we are actually scrolled right or down 1
- pixel. In this case, our coordinates are correctly transformed by ViewToQDPt,
- but QuickDraw doesn't know anything about gLongOffset, so it still draws
- patterns thinking that we are at (0, 0), instead of (1, 1).
-
- The solution was to appropriately set the origin so that patterns are drawn
- correctly aligned. This can be done by making sure that we set the origin to
- some value that will cause QuickDraw to perform in exactly the same way as if
- the origin were really at the value specified by gLongOffset. Since classic
- QuickDraw patterns repeat after 8 pixels, we can accomplish this task by making
- sure that gLongOffset is a multiple of 8, and setting the origin to compensate
- by setting it to gLongOffset MOD 8.
-
- Unfortunately, this will only work for classic QuickDraw pattersn that repeat
- after 8 pixels. With PixPats, this period can be any power of 2. In order to
- support them, we have to make sure that gLongOffset must be only a multiple of
- whatever power of 2 is being used. Ideally, therefore, we could like to make
- the chunkiness of gLongOffset to be as large as possible. On the other hand, we
- can make it too large, or else the amount by which we offset the origin in
- TView.Focus may overflow QuickDraw's limits. I think that a value of 1024 or
- 2048 should be sufficient enough to accomodate the largest of PixPats a
- developer may use, and still be small enough that we shouldn't overflow
- QuickDraw.
- }
-
- BEGIN
- Focus := TRUE;
-
- IF IsFocused THEN
- BEGIN
- {$IFC qDebug}
- GetPort(currentPort);
- IF GetGrafPort <> currentPort THEN
- ProgramBreak('TView.Focus: Port is incorrect');
- {$ENDC}
- Exit(Focus);
- END;
-
- {$IFC qExperimentalAndUnsupported}
- IF fFocusRec.IsValid THEN
- BEGIN
- aFocusRec := fFocusRec;
- SetFocus(aFocusRec);
- Exit(Focus);
- END;
- {$EndC}
-
- IF (gDrawingPictScrapView = SELF) | ((gCurrPrintHandler <> NIL) & (gCurrPrintHandler.fView =
- SELF)) THEN
- BEGIN
- { GrafPort has been supplied }
- gFocusedView := SELF;
- END
-
- ELSE IF FocusOnSuperView THEN
- BEGIN
- gFocusedView := SELF; { If I can focus on a superview then by
- definition I can focus on myself }
- GetFrame(myFrame); {!!! We do this enough. Really need a
- GetQDFrame }
- ViewToQDRect(myFrame, qdFrame); {Must be done before changing gLongOffset
- Really want to do the line below but it's
- late and viewEdit is getting cranky… Next
- release, really. }
- { NOPE fSuperView.ViewToQDRect(myFrame, qdFrame);} { Must be done while focused on superview
- }
-
- FOR vhs := v TO h DO
- IF fSize.vh[vhs] > kMaxCoord THEN
- BEGIN
- tempLongOffset := gLongOffset.vh[vhs] - fLocation.vh[vhs];
- relOrigin.vh[vhs] := tempLongOffset MOD kMaxOriginFixup;
- gLongOffset.vh[vhs] := tempLongOffset - relOrigin.vh[vhs];
- END
- ELSE
- BEGIN
- relOrigin.vh[vhs] := gLongOffset.vh[vhs] - fLocation.vh[vhs];
- gLongOffset.vh[vhs] := 0;
- END;
-
- WITH thePort^.portRect, relOrigin DO
- BEGIN
- SetOrigin(left + h, top + v);
- ClipFurtherTo(qdFrame, h, v);
- END;
-
- {$IFC qExperimentalAndUnsupported}
- aFocusRec.clip := fFocusRec.clip;
- GetFocus(aFocusRec);
- fFocusRec := aFocusRec;
- {$EndC}
- END
- ELSE
- BEGIN
- { If we get this far, then we can't focus }
- ClipRect(gZeroRect);
- InvalidateFocus;
- Focus := FALSE;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.FocusOnSuperView: BOOLEAN;
-
- BEGIN
- IF gDrawingPictScrap | gPrinting THEN
- FocusOnSuperView := TRUE
- ELSE IF fSuperview <> NIL THEN
- FocusOnSuperView := fSuperview.Focus
- ELSE
- FocusOnSuperView := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.ForceRedraw;
-
- VAR
- extent: VRect;
-
- BEGIN
- GetExtent(extent);
- InvalidVRect(extent);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TView.FreeFromClipboard;
-
- BEGIN
- IF fDocument <> NIL THEN
- fDocument.FreeFromClipboard
- ELSE
- Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAInspector}
-
- PROCEDURE TView.GetInspectorName(VAR inspectorName: Str255); OVERRIDE;
-
- VAR
- itsWindow: TWindow;
-
- BEGIN
- IF (fSuperview <> NIL) & IsObject(fSuperview) THEN
- BEGIN
- itsWindow := GetWindow;
- IF (itsWindow <> NIL) & IsObject(itsWindow) & (NOT ODD(ORD4(itsWindow.fWMgrWindow))) THEN
- BEGIN
- itsWindow.GetTitle(inspectorName);
- inspectorName := CONCAT('In ', inspectorName);
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.IsFocused: BOOLEAN;
-
- BEGIN
- IsFocused := gFocusedView = SELF;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.GetDialogView: TView;
-
- BEGIN
- IF fSuperview <> NIL THEN
- GetDialogView := fSuperview.GetDialogView
- ELSE
- GetDialogView := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.GetExtent(VAR itsExtent: VRect);
-
- BEGIN
- WITH itsExtent DO
- BEGIN
- topleft := gZeroVPt;
- botRight := fSize;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.GetFrame(VAR itsFrame: VRect);
-
- BEGIN
- WITH itsFrame DO
- BEGIN
- topleft := fLocation;
- botRight := topleft;
- {$Push} {$H-}
- AddVPt(fSize, botRight);
- {$Pop}
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.GetGrafPort: GrafPtr;
-
- BEGIN
- IF gPrinting | gDrawingPictScrap THEN
- GetGrafPort := thePort {thePort assumed to be set by print handler}
- ELSE IF fSuperview <> NIL THEN
- GetGrafPort := fSuperview.GetGrafPort
- ELSE
- GetGrafPort := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.GetPrintExtent(VAR printExtent: VRect);
-
- BEGIN
- GetExtent(printExtent);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.GetQDExtent(VAR qdExtent: Rect);
-
- VAR
- vr: VRect;
-
- BEGIN
- GetExtent(vr);
- ViewToQDRect(vr, qdExtent);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.GetScroller(immediateSuperView: BOOLEAN): TScroller;
-
- VAR
- aScroller: TScroller;
-
- BEGIN
- GetScroller := NIL;
- IF fSuperview <> NIL THEN
- BEGIN
- aScroller := fSuperview.GetScroller(immediateSuperView);
- IF (aScroller = fSuperview) | (NOT immediateSuperView) THEN
- GetScroller := aScroller;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.GetVisibleRect(VAR visQDRect: Rect);
-
- BEGIN
- GetQDExtent(visQDRect);
- VisibleRect(visQDRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.GetWindow: TWindow;
-
- BEGIN
- IF fSuperview <> NIL THEN
- GetWindow := fSuperview.GetWindow
- ELSE
- GetWindow := NIL;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- FUNCTION TView.GivePasteData(aDataHandle: Handle;
- dataType: ResType): LONGINT;
-
- VAR
- offset: LONGINT;
- err: LONGINT;
- savedPerm: BOOLEAN;
-
- BEGIN
- {Make sure the scrap handle is grown out of permanent memory. If it
- was grown out of temporary memory it would eat away at our
- code space.}
- savedPerm := PermAllocation(TRUE);
- err := GetScrap(aDataHandle, dataType, offset);
- savedPerm := PermAllocation(savedPerm);
-
- {$IFC qDebug}
- IF err < 0 THEN
- WRITELN('TView.GivePasteData got error code # ', err: 1, ' from GetScrap for type "',
- dataType, '"');
- {$ENDC}
- GivePasteData := err;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.HandleCursor(theMouse: VPoint;
- cursorRgn: RgnHandle): TView;
-
- VAR
- dummyView, viewThatHandledCursor: TView;
-
- FUNCTION TestMouse(theSubView: TView): BOOLEAN;
-
- VAR
- subViewPt: VPoint;
-
- BEGIN
- subViewPt := theMouse;
- theSubView.SuperToLocal(subViewPt);
-
- { don't give views on the clipboard a shot at claiming the cursor
- !!! need a better way to control which views get to claim the cursor
- don't need to test in DoSetCursor whether the view is the gClipView }
- IF theSubView.ContainsMouse(subViewPt) & (theSubView <> gClipView) THEN
- viewThatHandledCursor := theSubView.HandleCursor(subViewPt, cursorRgn);
-
- TestMouse := viewThatHandledCursor <> NIL;
- END;
-
- BEGIN
- {Assume if we got here then we already know the mouse is in this view}
- viewThatHandledCursor := NIL;
- dummyView := LastSubViewThat(TestMouse);
-
- IF (viewThatHandledCursor = NIL) & (SELF <> gClipView) THEN
- IF IsViewEnabled & Focus & DoSetCursor(ViewToQDPt(theMouse), cursorRgn) THEN
- BEGIN
- if qDebug & NOT EmptyRgn(cursorRgn) & NOT PtInRgn(ViewToQDPt(theMouse), cursorRgn) THEN
- BEGIN
- ProgramBreak('Mouse not in the cursor region when the cursor rgn is claimed');
- WrLblVPt('local cursor', theMouse);
- WrLblRect(' cursorRgn^^.rgnBBox', cursorRgn^^.rgnBBox);
- END;
-
- viewThatHandledCursor := SELF;
- END;
-
- HandleCursor := viewThatHandledCursor;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MASelCommand}
-
- FUNCTION TView.HandleMouseDown(theMouse: VPoint;
- VAR info: EventInfo;
- VAR hysteresis: Point;
- VAR theCommand: TCommand): BOOLEAN;
-
- VAR
- viewThatHandledMouse: TView;
- theQDMouse: Point;
-
- FUNCTION TestMouse(theSubView: TView): BOOLEAN;
-
- VAR
- subViewPt: VPoint;
-
- BEGIN
- subViewPt := theMouse;
- theSubView.SuperToLocal(subViewPt);
- IF theSubView.ContainsMouse(subViewPt) THEN
- TestMouse := theSubView.HandleMouseDown(subViewPt, info, hysteresis, theCommand)
- ELSE
- TestMouse := FALSE;
- END;
-
- BEGIN
- HandleMouseDown := FALSE;
- theCommand := NIL;
-
- {Assume if we got here then we already know the mouse is in this view}
-
- viewThatHandledMouse := LastSubViewThat(TestMouse);
-
- IF viewThatHandledMouse <> NIL THEN {a subview handled it}
- HandleMouseDown := TRUE
- ELSE IF IsViewEnabled & Focus THEN {see if we can handle it}
- BEGIN
- theQDMouse := ViewToQDPt(theMouse);
- theCommand := DoMouseCommand(theQDMouse, info, hysteresis);
- HandleMouseDown := TRUE;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.HasPendingUpdate: BOOLEAN;
-
- BEGIN
- IF fSuperview <> NIL THEN
- HasPendingUpdate := fSuperview.HasPendingUpdate
- ELSE
- HasPendingUpdate := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.InvalidRect(r: Rect);
-
- BEGIN
- IF Focus THEN
- BEGIN
- VisibleRect(r);
- InvalRect(r);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.InvalidVRect(viewRect: VRect);
-
- VAR
- r: Rect;
-
- BEGIN
- IF Focus THEN
- BEGIN
- ViewToQDRect(viewRect, r);
- InvalidRect(r);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.InvalidateFocus;
-
- PROCEDURE InvalidateAFocus(theView: TView);
-
- BEGIN
- theView.InvalidateFocus;
- END;
-
- BEGIN
-
- {$IFC qExperimentalAndUnsupported}
- { !!! no focus caching in this release. (2.0) }
- fFocusRec.IsValid := FALSE;
- SetEmptyRgn(fFocusRec.Clip);
- {$EndC}
-
- EachSubView(InvalidateAFocus);
-
- IF gfocusedview <> NIL THEN
- BEGIN
- IF gfocusedview = self THEN
- gfocusedview := NIL;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.isShown: BOOLEAN;
-
- BEGIN
- isShown := fShown; {??? Shouldn't we ask our superview? }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.IsViewEnabled: BOOLEAN;
-
- BEGIN
- IsViewEnabled := fViewEnabled;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.IsVisible: BOOLEAN;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$EndC}
-
- IsVisible := isShown & NOT EmptyRgn(thePort^.clipRgn);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.LastSubViewThat(FUNCTION TestSubView(theSubView: TView): BOOLEAN): TView;
-
- BEGIN
- {$Push} {$R-} { Look, its ok to type coerce a nil
- reference but the world gets really crazy
- if the TestSubView function (or something)
- frees the view that is returned. That's
- why we defeat the run-time coercion
- testing that is done if range checking is
- true. }
- IF fSubViews <> NIL THEN
- LastSubViewThat := TView(fSubViews.LastThat(TestSubView))
- ELSE
- LastSubViewThat := NIL;
- {$Pop}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.LocalToSuper(VAR thePoint: VPoint);
-
- BEGIN
- {$Push} {$H-}
- AddVPt(fLocation, thePoint);
- {$Pop}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.LocalToWindow(VAR thePoint: VPoint);
-
- BEGIN
- IF fSuperview <> NIL THEN
- BEGIN
- LocalToSuper(thePoint);
- fSuperview.LocalToWindow(thePoint);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.Locate(h, v: VCoordinate;
- invalidate: BOOLEAN);
-
- PROCEDURE NotifySubView(theSubView: TView);
-
- BEGIN
- theSubView.SuperViewMoved(invalidate);
- END;
-
- BEGIN
- IF (h <> fLocation.h) | (v <> fLocation.v) THEN
- BEGIN
- IF invalidate THEN
- ForceRedraw;
- fLocation.h := h;
- fLocation.v := v;
- InvalidateFocus; {Must re-focus because view moved.}
- gApplication.InvalidateCursorRgn; {Must re-calc cursor rgn.}
- IF invalidate THEN
- ForceRedraw;
-
- IF fSuperview <> NIL THEN
- fSuperview.SubViewMoved(SELF);
- EachSubView(NotifySubView);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.MakeFirstSubView(theSubView: TView);
-
- BEGIN
- IF fSubViews <> NIL THEN {there must be at least one subview}
- IF TView(fSubViews.First) <> theSubView THEN
- BEGIN
- fSubViews.Delete(theSubView);
- fSubViews.InsertFirst(theSubView);
- theSubView.ForceRedraw;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.MakeLastSubView(theSubView: TView);
-
- BEGIN
- IF fSubViews <> NIL THEN {there must be at least one subview}
- IF TView(fSubViews.Last) <> theSubView THEN
- BEGIN
- fSubViews.Delete(theSubView);
- fSubViews.InsertLast(theSubView);
- theSubView.ForceRedraw;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAOpen}
-
- PROCEDURE TView.Open;
-
- PROCEDURE OpenSubView(theSubView: TView);
-
- BEGIN
- theSubView.Open;
- END;
-
- BEGIN
- EachSubView(OpenSubView);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.PageInteriorChanged(newInterior: Rect);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.QDToViewPt(qdPoint: Point;
- VAR viewPt: VPoint);
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- PtToVPt(qdPoint, viewPt);
- AddVPt(gLongOffset, viewPt);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.QDToViewRect(qdRect: Rect;
- VAR viewRect: VRect);
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- RectToVRect(qdRect, viewRect);
- OffsetVRect(viewRect, gLongOffset.h, gLongOffset.v);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.RemoveSubView(theSubView: TView);
-
- VAR
- itsWindow: TWindow;
-
- BEGIN
- IF qDebug THEN
- FailNonObject(theSubView);
-
- IF fSubViews <> NIL THEN
- BEGIN
- fSubViews.Delete(theSubView);
- IF fSubViews.IsEmpty THEN { See if we need the list any more }
- BEGIN
- FreeIfObject(fSubViews);
- fSubViews := NIL;
- END;
- END;
-
- IF theSubView.fNextHandler = SELF THEN { If next event handler is the superview }
- theSubView.fNextHandler := NIL; { take it out of the event handler chain. }
-
- theSubView.fSuperview := NIL;
-
- theSubView.InvalidateFocus; { the new subview may have been focused }
-
- { !!! Patch up the target chain. This has to be done because we don't have any notification }
- { process. This will have to be fixed up later. }
- itsWindow := GetWindow;
- IF (itsWindow <> NIL) & (itsWindow.fTarget = theSubView) THEN
- itsWindow.SetTarget(SELF) { in the next release with better }
- ELSE IF theSubView = gTarget THEN
- gApplication.SetTarget(SELF);
-
- theSubView.BeInPort(NIL);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.Resize(width, height: VCoordinate;
- invalidate: BOOLEAN);
-
- VAR
- delta: VPoint;
- oldFrame, newFrame, InvalRect: VRect;
-
- PROCEDURE NotifySubView(theSubView: TView);
-
- BEGIN
- theSubView.SuperViewChangedSize(delta, invalidate);
- END;
-
- BEGIN
- IF (fSize.h <> width) | (fSize.v <> height) THEN
- BEGIN
- IF invalidate & Focus THEN
- GetFrame(oldFrame);
-
- SetVPt(delta, width - fSize.h, height - fSize.v);
- fSize.h := width;
- fSize.v := height;
-
- InvalidateFocus; {Must re-focus because size changed}
- gApplication.InvalidateCursorRgn; {Must re-calc cursor rgn.}
-
- IF invalidate & Focus THEN
- BEGIN
- GetFrame(newFrame);
-
- IF FocusOnSuperView THEN
- BEGIN
- IF oldFrame.right <> newFrame.right THEN { must invalidate width difference }
- BEGIN
- SetVRect(InvalRect, Min(oldFrame.right, newFrame.right), Min(oldFrame.top,
- newFrame.top), Max(oldFrame.right, newFrame.right),
- Max(oldFrame.bottom, newFrame.bottom));
- IF fSuperview <> NIL THEN
- fSuperview.InvalidVRect(InvalRect);
- END;
-
- IF oldFrame.bottom <> newFrame.bottom THEN { must invalidate height difference }
- BEGIN
- SetVRect(InvalRect, Min(oldFrame.left, newFrame.left), Min(oldFrame.bottom,
- newFrame.bottom), Max(oldFrame.right, newFrame.right),
- Max(oldFrame.bottom, newFrame.bottom));
- IF fSuperview <> NIL THEN
- fSuperview.InvalidVRect(InvalRect);
- END
- END;
- END;
-
- IF fSuperview <> NIL THEN
- fSuperview.SubViewChangedSize(SELF, delta);
- EachSubView(NotifySubView);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- PROCEDURE TView.RevealBottom(redraw: BOOLEAN);
-
- VAR
- rectToReveal: VRect;
-
- BEGIN
- rectToReveal.topleft := fSize;
- rectToReveal.botRight := fSize;
- RevealRect(rectToReveal, gZeroPt, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- PROCEDURE TView.RevealRect(rectToReveal: VRect;
- minToSee: Point;
- redraw: BOOLEAN);
-
- BEGIN
- IF fSuperview <> NIL THEN
- BEGIN
- OffsetVRect(rectToReveal, fLocation.h, fLocation.v);
- fSuperview.RevealRect(rectToReveal, minToSee, redraw);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAScroll}
-
- PROCEDURE TView.RevealTop(redraw: BOOLEAN);
-
- BEGIN
- RevealRect(gZeroVRect, gZeroPt, redraw);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.Show(state, redraw: BOOLEAN);
-
- BEGIN
- IF state <> fShown THEN
- BEGIN
- IF redraw THEN
- BEGIN
- fShown := TRUE; { So that ForceRedraw works. }
- ForceRedraw;
- END;
- InvalidateFocus;
- gApplication.InvalidateCursorRgn; {Must re-calc cursor rgn.}
- fShown := state;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAReadFile}
-
- PROCEDURE TView.ShowReverted;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE RevertSubView(theSubView: TView);
-
- BEGIN
- theSubView.ShowReverted;
- END;
-
- BEGIN
- AdjustSize;
- ForceRedraw;
- EachSubView(RevertSubView);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.SubViewChangedSize(theSubView: TView;
- delta: VPoint);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.SubViewMoved(theSubView: TView);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.SuperToLocal(VAR thePoint: VPoint);
-
- BEGIN
- {$Push} {$H-}
- SubVPt(fLocation, thePoint);
- {$Pop}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.SuperViewChangedSize(delta: VPoint;
- invalidate: BOOLEAN);
-
- VAR
- newSize: VPoint;
- needsResizing: BOOLEAN;
- vhs: VHSelect;
-
- BEGIN
- needsResizing := FALSE;
- newSize := fSize;
- FOR vhs := v TO h DO
- IF fSizeDeterminer[vhs] = sizeSuperView THEN
- needsResizing := TRUE
- ELSE IF fSizeDeterminer[vhs] = sizeRelSuperView THEN
- BEGIN
- newSize.vh[vhs] := newSize.vh[vhs] + delta.vh[vhs];
- needsResizing := TRUE;
- END;
-
- IF needsResizing THEN
- BEGIN
- ComputeSize(newSize);
- Resize(newSize.h, newSize.v, invalidate);
- DoPagination;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.SuperViewMoved(invalidate: BOOLEAN);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MADoCommand}
-
- FUNCTION TView.IsDoneTracking: BOOLEAN;
-
- BEGIN
- { Default to mouse-down tracking }
- IsDoneTracking := NOT StillDown;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MADoCommand}
-
- PROCEDURE TView.TrackConstrain(anchorPoint, previousPoint: VPoint;
- VAR nextPoint: VPoint);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MADoCommand}
-
- PROCEDURE TView.TrackFeedback(anchorPoint, nextPoint: VPoint;
- turnItOn, mouseDidMove: BOOLEAN);
-
- { Use code like this to get a flickering rectangle. }
-
- VAR
- r: Rect;
- vr: VRect;
-
- BEGIN
- IF mouseDidMove THEN
- BEGIN
- Pt2VRect(anchorPoint, nextPoint, vr);
- ViewToQDRect(vr, r);
- PenPat(Gray);
- FrameRect(r);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MADoCommand}
-
- PROCEDURE TView.TrackMouse(aTrackPhase: TrackPhase;
- VAR anchorPoint, previousPoint, nextPoint: VPoint;
- mouseDidMove: BOOLEAN);
-
- BEGIN
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.Update;
-
- BEGIN
- IF fSuperview <> NIL THEN
- fSuperview.Update
- ELSE
- DrawContents;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.ValidVRect(viewRect: VRect);
-
- VAR
- r: Rect;
-
- BEGIN
- IF Focus THEN
- BEGIN
- ViewToQDRect(viewRect, r);
- VisibleRect(r);
- ValidRect(r);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.ViewEnable(state, redraw: BOOLEAN);
-
- BEGIN
- fViewEnabled := state;
- IF redraw THEN
- ForceRedraw;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- FUNCTION TView.ViewToQDPt(viewPt: VPoint): Point;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- SubVPt(gLongOffset, viewPt);
- ViewToQDPt := VPtToPt(viewPt);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.ViewToQDRect(viewRect: VRect;
- VAR qdRect: Rect);
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- WITH gLongOffset DO
- OffsetVRect(viewRect, - h, - v);
- VRectToRect(viewRect, qdRect);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAViewRes}
-
- PROCEDURE TView.WindowToLocal(VAR thePoint: VPoint);
-
- BEGIN
- IF fSuperview <> NIL THEN
- BEGIN
- fSuperview.WindowToLocal(thePoint);
- SuperToLocal(thePoint);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MANonRes}
-
- PROCEDURE TView.WriteToDeskScrap;
-
- VAR
- pHndl: PicHandle;
- pictureIsOpen: BOOLEAN;
- qdExtent: Rect;
- err: LONGINT;
- tempPort: GrafPort;
- tempCPort: CGrafPort;
- fi: FailInfo;
-
- PROCEDURE HdlWriteToDeskScrap(error: OSErr;
- message: LONGINT);
-
- BEGIN
- IF pHndl <> NIL THEN
- BEGIN
- IF pictureIsOpen THEN
- ClosePicture;
- KillPicture(pHndl);
- END;
-
- IF qNeedsColorQD | gConfiguration.hasColorQD THEN
- CloseCPort(@tempCPort)
- ELSE
- ClosePort(@tempPort);
- SetPort(gWorkPort);
- BeInPort(NIL);
- gDrawingPictScrap := FALSE;
- gDrawingPictScrapView := NIL;
- END;
-
- BEGIN {!!! Really need to have AsPict method to
- render a view so anyone can call it }
- InvalidateFocus;
-
- gDrawingPictScrap := TRUE;
- gDrawingPictScrapView := SELF;
- IF qNeedsColorQD | gConfiguration.hasColorQD THEN
- BEGIN
- OpenCPort(@tempCPort);
- BeInPort(@tempCPort);
- END
- ELSE
- BEGIN
- OpenPort(@tempPort);
- BeInPort(@tempPort);
- END;
-
- CatchFailures(fi, HdlWriteToDeskScrap);
-
- IF Focus THEN
- BEGIN
- {Open color or black & white, depending on the port}
- GetQDExtent(qdExtent);
- pHndl := OpenPicture(qdExtent);
- pictureIsOpen := TRUE; { Failure handler needs to close it }
-
- IF pHndl <> NIL THEN
- BEGIN
- ClipRect(qdExtent);
- DrawContents;
- ClosePicture;
- pictureIsOpen := FALSE; { Failure handler doesn't need to close it }
-
- {On the 128K ROMs the picFrame will be empty if drawing the
- picture failed. On the 64K ROM's QuickDraw simply bombs.}
- IF EmptyRect(pHndl^^.picFrame) THEN
- BEGIN
- {$IFC qDebug}
- WRITELN('Picture frame is empty!');
- {$ENDC}
- Failure(memFullErr, 0);
- END;
-
- err := PutDeskScrapData('PICT', Handle(pHndl));
- KillPicture(pHndl);
- pHndl := NIL; { So failure handler doesn't to kill it }
-
- IF err <> NoErr THEN
- BEGIN
- {$IFC qDebug}
- ProgramBreak('Failed to put PICT-type scrap');
- {$ENDC}
- Failure(err, 0);
- END;
- END
- ELSE
- BEGIN
- {$IFC qDebug}
- ProgramBreak('Couldn''t 0penPicture during attempt to write PICT to desk scrap');
- {$ENDC}
- Failure(memFullErr, 0); {Assume cause of failure was lack of memory}
- END;
-
- InvalidateFocus;
- END
- {$IFC qDebug}
- ELSE { can't focus }
- ProgramBreak('Can''t focus view while writing picture to desk scrap');
- {$ENDC}
- ;
-
- Success(fi);
-
- IF qNeedsColorQD | gConfiguration.hasColorQD THEN
- CloseCPort(@tempCPort)
- ELSE
- ClosePort(@tempPort);
- SetPort(gWorkPort);
- gDrawingPictScrap := FALSE;
- gDrawingPictScrapView := NIL;
- BeInPort(NIL);
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TView.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TView', NIL, bClass);
- DoToField('fSuperView', @fSuperview, bObject);
- DoToField('fSubViews', @fSubViews, bObject);
- DoToField('fDocument', @fDocument, bObject);
- DoToField('fLocation', @fLocation, bVPoint);
- DoToField('fSize', @fSize, bVPoint);
- DoToField('fSizeDeterminer[h]', @fSizeDeterminer[h], bSizeDeterminer);
- DoToField('fSizeDeterminer[v]', @fSizeDeterminer[v], bSizeDeterminer);
- DoToField('fHLDesired', @fHLDesired, bHLState);
- DoToField('fIdentifier', @fIdentifier, bIDType);
- DoToField('fShown', @fShown, bBoolean);
- DoToField('fViewEnabled', @fViewEnabled, bBoolean);
- DoToField('fPrintHandler', @fPrintHandler, bObject);
-
- {$IFC qExperimentalAndUnsupported}
- DoToField('fFocusRec', NIL, bTitle);
- DoToField(' isValid', @gSaveFocusRec.IsValid, bBoolean);
- DoToField(' clip', @gSaveFocusRec.Clip, bRgnHandle);
- DoToField(' drawingPictScrap', @gSaveFocusRec.drawingPictScrap, bBoolean);
- DoToField(' drawingPictScrapView', @gSaveFocusRec.drawingPictScrapView, bObject);
- DoToField(' focusedView', @gSaveFocusRec.focusedView, bObject);
- DoToField(' longOffset', @gSaveFocusRec.longOffset, bVPoint);
- DoToField(' org', @gSaveFocusRec.org, bPoint);
- DoToField(' port', @gSaveFocusRec.port, bWindowPtr);
- DoToField(' printing', @gSaveFocusRec.printing, bBoolean);
- {$EndC}
-
- INHERITED Fields(DoToField);
- END;
-